# -*- coding: utf-8 -*-
from __future__ import annotations
from typing import Dict, Any, Callable
from pydantic import BaseModel, ValidationError

# ---- 工具实现 ----

class SumArgs(BaseModel):
    a: float
    b: float

def sum_tool(**kwargs) -> float:
    args = SumArgs(**kwargs)
    return float(args.a) + float(args.b)

# 供控制器调用的注册表
TOOL_FUNCS: dict[str, Callable[..., Any]] = {
    "sum": sum_tool,
}

# ---- 工具 JSON Schema 定义（给 LLM） ----
TOOLS_SPEC = [
    {
        "type": "function",
        "function": {
            "name": "sum",
            "description": "计算两数之和，返回 a+b。",
            "parameters": {
                "type": "object",
                "properties": {
                    "a": {"type": "number", "description": "加数1"},
                    "b": {"type": "number", "description": "加数2"},
                },
                "required": ["a", "b"],
                "additionalProperties": False
            }
        }
    }
]
